package me.raih.controller.admin.common;

import me.raih.pojo.po.Wares;
import me.raih.pojo.vo.PageBean;
import me.raih.pojo.vo.ResultInfo;
import me.raih.service.AppointmentService;
import me.raih.service.WaresService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author Raih
 * @Time 2021/3/31  21:30
 *
 * 预约管理
 */
@Controller
@RequestMapping(value = "/admin")
public class AdminAppointmentController {

    @Autowired
    AppointmentService appointmentService;

    @Autowired
    WaresService waresService;

    /**
     *
     * @return 去预约页面
     */
    @RequestMapping(value = "/appointment")
    public String toAppointmentPage(){

        return "admin/appointment/appointmentList";
    }

    @RequestMapping(value = "/findAppointmentList",method = RequestMethod.GET)
    @ResponseBody
    public ResultInfo appointmentMessage(@RequestParam("param") String param,
                                         @RequestParam("currentPage") int currentPage,
                                         @RequestParam("bigPage") int bigPage){
        ResultInfo resultInfo = new ResultInfo();
        int pageSize = 10;
        //查找 用户和商品关联的 map
        PageBean<Object> pageBean = appointmentService.findAppointmentList(currentPage, pageSize, param, bigPage);

        if(pageBean == null || pageBean.getList() == null || pageBean.getList().size() == 0){
            resultInfo.setFlag(false);
            resultInfo.setMessage("没有数据可以查询");
        }else {
            resultInfo.setFlag(true);
            resultInfo.setData(pageBean);
        }

        return resultInfo;
    }

    @RequestMapping(value = "/appointment/showWaresMessage")
    public String toWaresMessage(@RequestParam("no") String no, Model model){
        //查询预约的商品
        Wares wares = waresService.findWaresByNo(no);
        //给到页面
        model.addAttribute("APPOINTMENT_WARES",wares);
        return "admin/appointment/appointmentWares";
    }

}
